/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pb138.videodes.desktop;

import cz.muni.fi.pb138.videodes.entity.Genre;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.swing.AbstractListModel;

/**
 *
 * @author vaclav
 */
public class GenreListModel extends AbstractListModel {
    
    List<Genre> genres;
    
    public GenreListModel() {
        genres = new ArrayList<Genre>();
    }
    
    public GenreListModel(List<Genre> genres) {
        this.genres = genres;
        int row = this.genres.size();
        fireIntervalAdded(this, 0, row);
    }
    
    public void add(Genre genre) {
        genres.add(genre);
        
        int row = genres.size();
        fireIntervalAdded(this, row, row);
    }
    
    public void remove(Genre genre) {
        genres.remove(genre);
        int row = genres.size();
        fireIntervalRemoved(this, row, row);
    }
    
    public List<Genre> getAllGenres() {
        return Collections.unmodifiableList(genres);
    }

    @Override
    public int getSize() {
        return genres.size();
    }

    @Override
    public Object getElementAt(int i) {
        return genres.get(i);
    }
    
}
